<%@ taglib prefix="page" uri="http://com.qipay/pagelib" %>
<%@ page language="java" import="com.qipay.admin.cp.vo.CpPostDTO" contentType="text/html;charset=utf-8" %>
<%@ page import="com.qipay.security.UserDetailsServiceImpl" %>
<%@ page import="com.qipay.user.entity.UserLevel" %>
<!doctype html>
<html>
<head>
    <jsp:include page="head.jsp"></jsp:include>
</head>
<body class="hold-transition skin-blue sidebar-mini">
<div class="wrapper">
    <jsp:include page="nav.jsp"></jsp:include>
    <jsp:include page="left.jsp"></jsp:include>
    <!-- Content Wrapper. Contains page content -->
    <div class="content-wrapper">
        <!-- Main content -->
        <% CpPostDTO cpInfo = (CpPostDTO) request.getAttribute("detail");
            Boolean isAdd = String.valueOf(request.getAttribute("isadd")).equals("1");
            UserDetailsServiceImpl.LoginUserDetails userDetails = (UserDetailsServiceImpl.LoginUserDetails) request.getAttribute("admin");
        %>

        <section class="content">
            <div class="row">
                <div class="col-xs-12">
                    <div class="box box-info">
                        <div class="box-header with-border">
                            <h3 class="box-title">修改登录密码</h3>
                        </div>
                        <!-- /.box-header -->
                        <!-- form start -->
                        <form class="form-horizontal" action="save" method="POST" id="doc-vld-msg">

                            <div class="box-body" id="dvContent">
                                <div class="form-group">
                                    <label for="txtOldPwd" class="col-sm-2 control-label">旧密码：</label>
                                    <div class="col-sm-10">
                                        <input type="password" id="txtOldPwd" maxlength="20" name="oldPwd"
                                               data-validation-message="输入旧密码" required>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label for="txtNewPwd" class="col-sm-2 control-label">新密码：</label>
                                    <div class="col-sm-10">
                                        <input type="password" id="txtNewPwd" maxlength="20" name="newPwd"
                                               data-validation-message="输入新密码" required>

                                    </div>
                                </div>
                                <div class="form-group">
                                    <label for="txtConfirmPwd" class="col-sm-2 control-label">确认密码：</label>
                                    <div class="col-sm-10">
                                        <input type="password" id="txtConfirmPwd" maxlength="20" name="confirmPwd"
                                               data-validation-message="输入确认密码" required>
                                    </div>
                                </div>

                            <!-- /.box-body -->
                            <div class="box-footer">
                                <button type="button" class="btn btn-default" onclick="window.history.back()">返回
                                </button>
                                <button type="button" class="button back-green pull-right" id="btnSearch">确 定</button>
                            </div>
                            <!-- /.box-footer -->
                            </div>
                        </form>
                    </div>
                    <!-- /.box -->
                </div>
                <!-- /.col -->
            </div>
            <!-- /.row -->
        </section>
        <!-- /.content -->
    </div>
    <!-- /.content-wrapper -->
    <jsp:include page="foot.jsp"></jsp:include>
</div>
<script src="<%= request.getAttribute("StaticHost") %>/js/fastclick.js"></script>
<script src="<%= request.getAttribute("StaticHost") %>/js/adminlte.min.js"></script>
<script>
    $(function () {

        $("#btnSearch").on("click", function () {
            var txtOldPwd = $.trim($("#txtOldPwd").val()) || "";
            var txtNewPwd = $.trim($("#txtNewPwd").val()) || "";
            var txtConfirmPwd = $.trim($("#txtConfirmPwd").val()) || "";
            if (txtOldPwd == "") {
                alert("请输入旧密码");
                return false;
            }
            if (txtNewPwd == "") {
                alert("请输入新密码");
                return false;
            }
            if (txtConfirmPwd != txtNewPwd) {
                alert("两次密码不一致");
                return false;
            }
            var that = this;
            $(that).attr("disabled", "disabled");
            $.ajax({
                type: 'POST',
                url: contextPath + "/sys/changepwd-save",
                data: {oldPwd: txtOldPwd, newPwd: txtNewPwd, confirmPwd: txtConfirmPwd},
                dataType: "json",
                success: function (data) {
                    if (data) {
                        if (data.code == 200) {
                            alert(data.msg);
                            $("#txtOldPwd").val('');
                            $("#txtNewPwd").val('');
                            $("#txtConfirmPwd").val('');
                            $(that).removeAttr("disabled");
                            alter("修改成功");
                            return;
                        }
                        alert(data.msg);
                        $(that).removeAttr("disabled");
                    } else {
                        alert('服务器异常，请稍后再试！')
                        $(that).removeAttr("disabled");
                    }
                },
                error: function () {
                    alert('服务器异常，请稍后再试！!')
                    $(that).removeAttr("disabled");
                }
            })
        });

    })
</script>
</body>
</html>

